﻿package app.view.components.sections.children 
{
	
	import app.model.RemoteProxy;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.RamkaImageD;
	import app.view.components.header.HeadMarkerBase;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.events.MouseEvent;
	
	/**
	 * 2.1.2 ПОБЕДИТЕЛИ
	 * firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class ChildrenCompetitionWinersMBase extends LabeledSectionBase
	{
		// app.view.components.sections.children.ChildrenCompetitionWinersMBase
		
		public var interveiwBtn:GlamurBtnBase;
		public var stagesBtn:GlamurBtnBase;
		
		// рамки
		private var _ramkiArray:/*RamkaImageD*/Array;
		public var ramka_01:RamkaImageD;
		public var ramka_02:RamkaImageD;
		public var ramka_03:RamkaImageD;
		public var ramka_04:RamkaImageD;
		public var ramka_05:RamkaImageD;
		public var ramka_06:RamkaImageD;
		public var ramka_07:RamkaImageD;
		public var ramka_08:RamkaImageD;
		public var ramka_09:RamkaImageD;
		public var ramka_10:RamkaImageD;
		private var _imageArray:Array;
		private var _videoItemArray:Array;
		
		public function ChildrenCompetitionWinersMBase() 
		{
			super();
		}
		
		override protected function init():void
		{
			super.init();
			
			_ramkiArray = new Array();
			
			_ramkiArray = [ramka_01,ramka_02,ramka_03,ramka_04,ramka_05,ramka_06,ramka_07,ramka_08,ramka_09,ramka_10];
			
			for (var i:int = 0; i < _ramkiArray.length; i++) 
			{
				_ramkiArray[i].id = i;
			}
		}
		
		private function setEvents():void
		{
			stagesBtn.addEventListener(MouseEvent.MOUSE_DOWN, onCLickCompetitionStage);
			interveiwBtn.addEventListener(MouseEvent.MOUSE_DOWN, onCLickInterviewWiners);
			
			addEventListener(UIEvent.CLICK_ITEM_EVENT, onClickRamka, true);
		}
		
		private function removeEvents():void
		{
			stagesBtn.removeEventListener(MouseEvent.MOUSE_DOWN, onCLickCompetitionStage);
			interveiwBtn.removeEventListener(MouseEvent.MOUSE_DOWN, onCLickInterviewWiners);
			
			removeEventListener(UIEvent.CLICK_ITEM_EVENT, onClickRamka, true);
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			stagesBtn.destroy();
			interveiwBtn.destroy();
			
			for (var i:int = 0; i < _ramkiArray.length; i++) 
			{
				_ramkiArray[i].destroy();
			}
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			setParamHead(HeadMarkerBase.BGD_ORANGE,String(_data.data.datawiner.head[1].text).substr(1));
			
			stagesBtn.setLang(data.lang);
			interveiwBtn.setLang(data.lang);
			
			_imageArray = new Array();
			
			//trace('data!!!', _data.data.cat[1].img[1].image[1].image_path);
			
			_videoItemArray = new Array();
			
			var arr:Array = new Array();
			var ind:int = 0;
			for each(var object:* in _data.data.datavideo.video_extends)
			{
				//trace('ddd', object.flv[1].flv_path);
				var objInfo:Object = new Object();
				objInfo.id 			= ind;
				// ???
				objInfo.image 		= RemoteProxy.DOMEN + _data.data.datawiner.img[ind+1].image[1].image_path;
				//---------------------
				objInfo.flv = (object.flv[1].flv_path != '') ? RemoteProxy.DOMEN + object.flv[1].flv_path : null;
				
				objInfo.text_video 	= object.text[1];
				objInfo.text_image 	= object.text[2];
				objInfo.text_fio 	= object.text[3];
				
				arr.push( objInfo );
				ind++;
			}
			
			// провери чтобы не было больше десяти? nfr crfpfnm juhfybxtybt
			for (var i:int = 0; i < 10; i++) 
			{
				_videoItemArray.push( arr[i] );
			}
			arr = null;
			
			
			for each(var objectImage:* in _data.data.datawiner.img)
			{
				var urlImage:String = (objectImage.image[1].image_path != '') ? (RemoteProxy.DOMEN + objectImage.image[1].image_path) : null;
				
				_imageArray.push( { image:urlImage } );
				//trace('55',object.image[1].image_path);
			}
			
			
			for (var k:int = 0; k < _imageArray.length; k++) 
			{
				_ramkiArray[k].setUrlImage(_imageArray[k].image);
			}
			
			setEvents();
		};
		
		/**
		 * переход этапы проведения конкурса
		 * @param	e
		 */
		private function onCLickCompetitionStage(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_COMPETITION_STAGES;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * переход интервью победителей
		 * @param	e
		 */
		private function onCLickInterviewWiners(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_INTERVIEW_WINERS;
			obj.currentId = id;
			obj.params = null;
			
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * вскрываем попап
		 * @param	e
		 */
		private function onClickRamka(e:UIEvent):void 
		{
			//trace('click',e.id);
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.POPUP_CHILDREN_WINER_INTERVIEW;
			obj.currentId = String(e.id);
			obj.params = data;
			obj.data = _videoItemArray;
			
			var ev:UIEvent = new UIEvent(UIEvent.POPUP_OPEN);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
		
	}

}